$(function() {
	var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块

	//监听导航点击
	element.on('nav(header_nav)', function(elem) {
		console.log(elem);
		// layer.msg(elem.text());
	});

	element.render();

	if (isSuper) {
		$("#tiosite_header_yk").css("display", "");
	}

	/**
	 * 根据登录状态显示"登录按钮"或是"用户信息"
	 */
	try {
		if (isLogined) {
			document.getElementById('tiosite_user_avatar').src = res_url(curruser.avatar);
			document.getElementById('tiosite_user_nick').innerHTML = curruser.nick;

			$("#show_login_register_btn").hide();
			$("#tiosite_header_avatar").show();
		} else {
			if ($("#login_and_register").length > 0) {
				$("#show_login_register_btn").show();
			}

			$("#tiosite_header_avatar").hide();
			
		}
	} catch (e) {
		error(e);
	}

	/**
	 * 设置头部导航当前样式
	 */
	try {
		var p = getRequestPath();
		// var nv_ul = document.getElementById("tiosite_header_nv_ul");
		var lis = $('#tiosite_header_nv_ul li a');
		lis.each(function() {
			if (p == $(this).attr('href')) {
				var pret = $(this).parent();
				for (var index = 0; index < 5; index++) {
					if (pret[0].tagName == 'LI') {
						pret.addClass('layui-this');
						return false;
					} else {
						pret = pret.parent();
						continue;
					}
				}
			}
		});
	} catch (error) {}

	layui
		.$('[login-tip]')
		.on('mouseenter', function() {
			this.index = layer.tips(
				'注册成为t-io社区用户，成为见证社区从无到有的元老级用户<p style="text-align:right;">—— t-io</p>',
				this,
				{
					time: -1,
					maxWidth: 280,
					tips: [3, '#3A3D49'],
				}
			);
		})
		.on('mouseleave', function() {
			layer.close(this.index);
		});

	layui
		.$('[logo-tip]')
		.on('mouseenter', function() {
			this.index = layer.tips(
				'九年打磨：是为解决自己的疼点<br>永久开源：希望同行们少踩点坑<p style="text-align:right;">—— t-io</p>',
				this,
				{
					time: -1,
					maxWidth: 280,
					tips: [3, '#3A3D49'],
				}
			);
		})
		.on('mouseleave', function() {
			layer.close(this.index);
		});
});

/**
 * 切换头部的fixed
 * param fix，true时表示要固定
 */
function tiosite_header_notfix(fix) {
	if (!fix) {
		$("#tiosite_header_row").removeClass("tio-site-header-fixed");//.removeAttr().css("position","rel");
		$("#tiosite_header_zh").css("display", "none");
	} else {
		$("#tiosite_header_row").addClass("tio-site-header-fixed");//.removeAttr().css("position","rel");
		$("#tiosite_header_zh").css("display", "");
	}
}
